import Axios from 'axios';
import MutationType from './mutationType';

export const state = () => ({
    tabbarState: true,
    comingSoonListState: []
});

export const getters = {
    comingSoonListGetter(state) {
        return state.comingSoonListState.filter((item, index) => index < 3);
    }
};

export const mutations = {
    tabbarMutation(state, data) {
        state.tabbarState = data;
    },
    // 动态配置mutation的名字
    [MutationType.GET_COMINGSONG_MUTATION](state, data) {
        state.comingSoonListState = data;
    }
};

export const actions = {
    getComingSongAction(store) {
        Axios({
            url: 'https://m.maizuo.com/gateway?cityId=370100&pageNum=1&pageSize=10&type=2&k=9149434',
            method: 'GET',
            headers: {
                'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.0.4","e":"159668407331181462568961","bc":"370100"}',
                'X-Host': 'mall.film-ticket.film.list'
            }
        }).then((res) => {
            store.commit(MutationType.GET_COMINGSONG_MUTATION, res.data.data.films);
        });
    }
};
